# -*- coding: UTF-8 -*-
'''
Created on 2012-6-21
文件备份
@author: Administrator
'''
import os
import time

source = [r'F:\pythondemo', r'F:\c_codeing']
target_dir = 'F:/pythondemo/'
def backupVer1():
    ''' File Backup Version 1
    
          文件备份 '''
   
    target = target_dir + time.strftime('%Y%m%d%H%M%S') + '.zip'
    zip_command = "zip -qr %s %s" % (target, ' '.join(source))
     
    if os.system(zip_command) == 0:
        print '备份成功,备份文件路径:' + target
    else:
        print '备份失败'
def backupVer2():
    ''' File Backup Version 2
    
          文件备份 '''
    
    today = target_dir + time.strftime('%Y%m%d') 
    now = time.strftime('%H%M%S') 
    
    if not os.path.exists(today):
        os.mkdir(today)
        print 'Create directory', today
    target = today + os.sep + now + ".zip"
    zip_command = "zip -qr %s %s" % (target, ' '.join(source))
     
    if os.system(zip_command) == 0:
        print '备份成功,备份文件路径:' + target
    else:
        print '备份失败'
def backupVer3():
    ''' File Backup Version 2
    
          文件备份 '''
    
    today = target_dir + time.strftime('%Y%m%d') 
    now = time.strftime('%H%M%S') 
    comment = raw_input('Enter a comment --> ')
    if len(comment) == 0: # check if a comment was entered
      target = today + os.sep + now + '.zip'
    else:
      target = today + os.sep + now + '_' + \
        comment.replace(' ', '_') + '.zip'
    if not os.path.exists(today):
        os.mkdir(today)
        print 'Create directory', today
     
    zip_command = "zip -qr %s %s" % (target, ' '.join(source))
     
    if os.system(zip_command) == 0:
        print '备份成功,备份文件路径:' + target
    else:
        print '备份失败'
if __name__ == '__main__':
    #backupVer1()
    #backupVer2()
    backupVer3()
